<html>
<head><meta charset="utf-8"><title>Infer hidden types without replacing with  compiler-team#325 · t-compiler/major changes · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/index.html">t-compiler/major changes</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html">Infer hidden types without replacing with  compiler-team#325</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202631099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202631099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202631099">(Jul 01 2020 at 22:26)</a>:</h4>
<p>A new proposal has been announced: <a href="https://github.com/rust-lang/compiler-team/issues/325">#325</a>. It will be<br>
                announced at the next meeting to try and draw attention to it,<br>
                but usually MCPs are not discussed during triage meetings. If<br>
                you think this would benefit from discussion amongst the<br>
                team, consider proposing a design meeting.</p>



<a name="202631126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202631126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202631126">(Jul 01 2020 at 22:27)</a>:</h4>
<p>I'd like to get feedback on this idea from <span class="user-mention" data-user-id="119009">@eddyb</span> <span class="user-mention" data-user-id="124288">@oli</span> and <span class="user-mention" data-user-id="116118">@Matthew Jasper</span>, at minimum =)</p>



<a name="202631152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202631152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202631152">(Jul 01 2020 at 22:27)</a>:</h4>
<p>I'd also like to know if people can come up with other examples that cause problems</p>



<a name="202631164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202631164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202631164">(Jul 01 2020 at 22:27)</a>:</h4>
<p>oh so this was one of the designs I think</p>



<a name="202631207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202631207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202631207">(Jul 01 2020 at 22:28)</a>:</h4>
<p>this stuff dropped off my radar but it makes sense</p>



<a name="202631257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202631257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202631257">(Jul 01 2020 at 22:28)</a>:</h4>
<p>My motivation is that I'd like to push impl trait to stabilization and elegantly handling these situations seems like the major blocker</p>



<a name="202631264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202631264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202631264">(Jul 01 2020 at 22:29)</a>:</h4>
<p>anyway g2g for now :) dinner time! <span aria-label="food" class="emoji emoji-1f372" role="img" title="food">:food:</span></p>



<a name="202631286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202631286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202631286">(Jul 01 2020 at 22:29)</a>:</h4>
<p>I guess this is simpler than other ways that use inference variables</p>



<a name="202656288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202656288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202656288">(Jul 02 2020 at 07:05)</a>:</h4>
<p>so... this is basically limiting the effect of opaque type restriction to the sites that actually go from an opaque type to a concrete type or vice versa, otherwise using the same opaque type everywhere (by letting inference carry it). So...</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">42</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">z</span>: <span class="nc">OpaqueTy</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y</span><span class="p">;</span><span class="w"></span>
</code></pre></div>


<p>what type will be inferred for <code>y</code>? the concrete type? and then only the <code>z = y</code> assignment will actually do any of the constraining of the opaque type to the concrete type?</p>



<a name="202656400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202656400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202656400">(Jul 02 2020 at 07:06)</a>:</h4>
<p>You posted a breaking change example but I don't quite get how it will break</p>



<a name="202691817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202691817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202691817">(Jul 02 2020 at 13:59)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> the type inferred for <code>y</code> would be <code>i32</code>, yes, and then assigning to <code>z</code> would create a constraint that <code>OpaqueTy = i32</code> basically</p>



<a name="202691832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202691832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202691832">(Jul 02 2020 at 14:00)</a>:</h4>
<p>but the type for <code>z</code> would be <code>OpaqueType</code></p>



<a name="202691895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202691895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202691895">(Jul 02 2020 at 14:00)</a>:</h4>
<p>similar to if you did</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">z</span>: <span class="nc">impl</span><span class="w"> </span><span class="n">Debug</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="202692061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202692061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202692061">(Jul 02 2020 at 14:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325/near/202656400">said</a>:</p>
<blockquote>
<p>You posted a breaking change example but I don't quite get how it will break</p>
</blockquote>
<p>well, it doesn't <em>necessarily</em> break, but if we do it naively it will. You can kind of observe the same effect if you re-order the return statements. In that case, we initially infer the return type to <code>Box&lt;i32&gt;</code> and then get an error because we are returning a <code>Box&lt;dyn Debug&gt;</code>.</p>
<p>In the same way, if we do the naive thing, we'll end up with two constraints:</p>
<ul>
<li><code>OpaqueType = Box&lt;i32&gt;</code></li>
<li><code>OpaqueType = Box&lt;dyn Debug&gt;</code></li>
</ul>
<p>and we'll get an error because they are incompatible constraints.</p>
<p>For the example to work, we have to figure out that a coercion is possible and apply it to one of the return statements.</p>



<a name="202974651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/202974651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#202974651">(Jul 06 2020 at 10:45)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="492">@T-compiler</span>: Proposal <a href="https://github.com/rust-lang/compiler-team/issues/325#issuecomment-654158174">#325</a> has been seconded, and will be approved in 10 days if no objections are raised.</p>



<a name="203012897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/203012897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#203012897">(Jul 06 2020 at 16:44)</a>:</h4>
<p>I'm a bit confused as to how this is supposed to work. From what I can tell we have:</p>
<ul>
<li>If we have <code>known == Opaque</code> or <code>known &lt;: Opaque</code> we generate a predicate</li>
<li>If we have <code>_ == Opaque(...)</code> or <code>_ &lt;: Opaque(...)</code> then we unify directly</li>
</ul>
<p>Given that I'm not sure how we handle:</p>
<ul>
<li>The same opaque type with different substs (admittedly we don't handle that currently either)</li>
<li>If <code>Opaque</code> everything unifies with everything, how does selection not break.</li>
</ul>



<a name="203033792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/203033792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#203033792">(Jul 06 2020 at 20:00)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> Selection is a good question. I did think about that at some point but it looks like I neglected to talk about it in the MCP, and now that I think a bit more about it I'm not sure that the idea I had actually makes sense.</p>



<a name="203033883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/203033883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#203033883">(Jul 06 2020 at 20:01)</a>:</h4>
<p>I guess a question would be what amount of trait selection we expect to succeed</p>



<a name="203033899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/203033899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#203033899">(Jul 06 2020 at 20:01)</a>:</h4>
<p>i.e., just where can the contraints come from?</p>



<a name="203033946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/203033946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#203033946">(Jul 06 2020 at 20:01)</a>:</h4>
<p>I was imagining that trait selection might operate in a "syntactic mode" where traits are dispatched based only on the declared bounds of the opaque type.</p>



<a name="203034038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/203034038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#203034038">(Jul 06 2020 at 20:02)</a>:</h4>
<p>i.e., even if you are inside the "inference region", you can't prove that a value of the opaque type implements more trait than its bounds.</p>



<a name="203035601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/203035601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#203035601">(Jul 06 2020 at 20:16)</a>:</h4>
<p>I suppose that this is to some extent also a T-lang issue ("what behavior do we expect")</p>



<a name="204682920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/204682920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#204682920">(Jul 22 2020 at 15:39)</a>:</h4>
<p>This proposal has been accepted: <a href="https://github.com/rust-lang/compiler-team/issues/325">#325</a>.</p>



<a name="204708722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/204708722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#204708722">(Jul 22 2020 at 19:02)</a>:</h4>
<p>A new proposal has been announced: <a href="https://github.com/rust-lang/compiler-team/issues/325">#325</a>. It will be announced at the next meeting to try and draw attention to it, but usually MCPs are not discussed during triage meetings. If you think this would benefit from discussion amongst the team, consider proposing a design meeting.</p>



<a name="204708783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Infer%20hidden%20types%20without%20replacing%20with%20%20compiler-team%23325/near/204708783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Infer.20hidden.20types.20without.20replacing.20with.20.20compiler-team.23325.html#204708783">(Jul 22 2020 at 19:03)</a>:</h4>
<p>This has open concerns</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>